package cn.ziroom.system.service;

import java.util.List;

import cn.common.util.GeneralUtils;
import cn.ziroom.system.domain.User;
import cn.ziroom.system.mapper.UserMapper;

/**
 * 系统用户管理业务处理类
 * 
 * @author Administrator
 * 
 */
public class UserService {

	public static String USER_KEY = "user";

	private UserMapper userMapper;

	/**
	 * 同步用户数据访问业务处理方法
	 * 
	 * @param list
	 * @return
	 */
	public String synchroUser(List<User> list) {
		for (User user : list) {
			String code = userMapper.selectByCode(user.getStaffid());
			if (code != null) {
				userMapper.update(user);
			} else {
				userMapper.insert(user);
			}
		}
		return "success";
	}


	/**
	 * 用户查询
	 * 
	 * @param user
	 * @return
	 */
	public String searchUser(User user) {
		return GeneralUtils.easyUI(userMapper.count(user), userMapper.selectList(user));
	}

	/**
	 * 查找用户
	 * 
	 * @param user
	 * @return
	 */
	public User findUser(User user) {
		user = userMapper.selectById(user.getId());
		return user;
	}

	/**
	 * 保存用户
	 * 
	 * @param user
	 */
	public void saveUser(User user) {
		userMapper.updateUser(user);
	}


	/**
	 * 根据编号查询用户
	 * 
	 * @param staffId
	 * @return
	 */
	public User searchUserByStaffId(String staffId) {
		return userMapper.searchUserByStaffId(staffId);
	}

	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}
}
